package thread.communication;

import static java.lang.System.out;

/**
 * 
 * @author Shahid
 */
public class Join implements Runnable {
	static int[] array = new int[10];

	public void run() {
		try {

			for (int j = 0; j < 10; j++) {
				array[j] = j;
				Thread.sleep(1);
			}
		} catch (InterruptedException e) {
			out.println(e.toString());
		}
	}

	// return array
	public int[] getArray() {
		return array;
	}
	
	// Print array
	static void print() {
		for (int i : array) {
			out.print(i + ",");
		}
		out.print("\n");
	}

	public static void main(String[] args) {
		
		Thread t = new Thread(new Join());
		t.start();

		out.println("Output without Join");
		print();

		try {
			t.join();
		} catch (InterruptedException ex) {
			out.println(ex.toString());
		}
		
		out.println("Output after Join");
		print();
		
	}
}

// Output without Join
// 0,0,0,0,0,0,0,0,0,0,
// Output after Join
// 0,1,2,3,4,5,6,7,8,9,

